package com.upic.serviceImpl;

import com.upic.po.jurisdiction.Jurisdiction;
import com.upic.repository.JurisdictionRepository;
import com.upic.service.JurisdictionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhubuqing on 2018/2/7.
 */
@Service("jurisdictionService")
public class JurisdictionServiceImpl implements JurisdictionService {
    @Autowired
    private JurisdictionRepository jurisdictionRepository;

    @Override
    public Jurisdiction saveJurisdiction(Jurisdiction jurisdiction) {
        return jurisdictionRepository.save(jurisdiction);
    }

    @Override
    public String deleteJurisdiction(long jurisdictionId) {
        jurisdictionRepository.delete(jurisdictionId);
        return "SUCCESS";
    }

    @Override
    public Page<Jurisdiction> searchJurisdiction(Pageable pageable) {
        return jurisdictionRepository.findAll(pageable);
    }

    @Override
    public List<Jurisdiction> searchJurisdiction() {
        return jurisdictionRepository.findAll();
    }

    @Override
    public Jurisdiction findOne(long jurisdictionId) {
        return jurisdictionRepository.findOne(jurisdictionId);
    }

    @Override
    public Jurisdiction updateJurisdiction(Jurisdiction jurisdiction) {
        return jurisdictionRepository.saveAndFlush(jurisdiction);
    }
}
